package com.atguigu.java.ai.langchain4j.config;

import com.atguigu.java.ai.langchain4j.store.MongoChatMemoryStore;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.service.MemoryId;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:Simple
 * @Date: 2025/8/29 18:49
 * @Description:
 **/
@Configuration
public class ChatMemoryIsolationConfig {
    /**
     * @author: Simple
     * @date: 2025-08-29 18:59:59
     * @description: 兼备记忆和隔离功能 匿名内部类写法
     */
//    @Bean
//    public ChatMemoryProvider chatMemoryIsolation(){
//        return  new ChatMemoryProvider() {
//            @Override
//            public ChatMemory get(Object memoryId) {
//                return MessageWindowChatMemory.builder()
//                        .id(memoryId)
//                        .maxMessages(10)
//                        .build();
//            }
//        };
//    }
    /**
     * @author: Simple
     * @date: 2025-08-29 19:05:33
     * @description: 当需要得到一个接口且接口只有一个方法时 可以使用lambda表达式
     */
    @Bean
    public ChatMemoryProvider chatMemoryIsolation(){
        return  memoryId->MessageWindowChatMemory.builder()
                .maxMessages(10)
                .id(memoryId)
                .build();
    }
}
